X-MIME-Autoconverted: from quoted-printable to 8bit by baskerville.CS.Arizona.EDU id eA1HUH311489
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 1873
In the spirit of the times, and in view of the apparent arrival of a lot of newcomers to Icon, let me also submit a fave of mine.
I write a lot of rather simple batch-oriented stuff (read a line, operate on the line, write something, repeat). A comment convention is just as useful with such data as with any programming language. Your data files can now be self-documenting without interfering with the program that needs to understand their formatting.
Here is a routine that implements a simple comment convention just like Icon's, so that every program I write is consistent in that respect. It is simple stuff, but I have come to rely on its presence in my library. Here it is, with a simple main() to drive it, and some test data for it. To test it, just enter the command
nocomm <nocomm.in >nocomm.out
THE PROGRAM (save as nocomm.icn):
procedure main()
while line := nocomm(&input) do
write(line)
exit(0)
end
# nocomm - implement a basic comment convention
procedure nocomm(f)
static line
while line := read(f) do {
line ? {
ws()
if ="#" | pos(0) then next
return trim(tab(upto('#') | 0))
}
}
fail
end
# ws - skip white space (blanks and tabs)
procedure ws()
tab(many(' \t'))
end
INPUT (save as nocomm.in):
This file shows how nocomm() implements a comment convention.
The following is a blank line.
It should be gone. nocomm() removes blank lines.
This line contains a comment. # It's too darn hot.
The next line is a comment.
# Slooooowly I turned, step by step.
The next line is also a comment.
# hello.
This is the last line.
OUTPUT (nocomm.out):
This file shows how nocomm() implements a comment convention.